package com.sqstudio.exercise.chapter3{
	
	import flash.events.Event;
	
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.view.BasicView;

	[SWF(width="800",height="600")]
	public class VerticesExample extends BasicView
	{
		private var pivotDO3D:DisplayObject3D;
		public function VerticesExample(viewportWidth:Number=800, viewportHeight:Number=600, scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String="Target")
		{
			super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
			stage.frameRate = 40;
			init();
			
			this.startRendering();
		}
		
		private function init():void{
			this.pivotDO3D = new DisplayObject3D();
			scene.addChild(pivotDO3D);
			var bigSphere:Sphere = new Sphere(null,500);
			var len:int = bigSphere.geometry.vertices.length;
			for (var i:int = 0; i <len; i++) 
			{
				var smallSphere:Sphere = new Sphere(null,int(Math.random() * 30));
				smallSphere.x = bigSphere.geometry.vertices[i].x;
				smallSphere.y = bigSphere.geometry.vertices[i].y;
				smallSphere.z = bigSphere.geometry.vertices[i].z;
				pivotDO3D.addChild(smallSphere);
			}
			pivotDO3D.localRotationX = -45;
			
		}
		
		override protected function onRenderTick(event:Event=null):void
		{
			pivotDO3D.localRotationY ++;
			super.onRenderTick(event);
		}
	}
}